home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- File: OSAPlugIn.cpp
-
- Contains: OSAPlugIn class implementation
-
- Written by: Sue Dumont
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- ------------------------------------------------------------------------------*/
-
- // -- Compiler/Preprocessor Notification --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- OSAPlugIn Includes --
-
- #ifndef SOM_Sample_ScriptRunnerAgent_xh
- #include "ScriptRunnerAgent.xh"
- #endif
-
- #ifndef _OSAPLUGINDEF_
- #include "OSAPlugInDef.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _SHPLUGIN_
- #include <ShPlugIn.h>
- #endif
-
- #ifndef SOM_M_ODObject_xh
- #include <ODObject.xh>
- #endif
-
- #ifndef SOM_ODObjectNameSpace_xh
- #include <ObjectNS.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODNEW_
- #include <ODNew.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- // -- Macintosh Includes --
-
- #ifndef __APPLESCRIPT__
- #include <AppleScript.h>
- #endif
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- // The pragma exports are needed for Symantec projects.
- #pragma export on
- OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft, ODShellPlugInActionCodes* action);
- #pragma export off
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #pragma segment ScriptRunnerAgent
-
- //------------------------------------------------------------------------------
- // Method: Install
- //
- // Description: Instantiate the ScriptRunnerAgent object and register it
- // into the Object Name Space.
- //------------------------------------------------------------------------------
-
- OSErr ODShellPlugInInstall( Environment* ev, ODDraft* draft,
- ODShellPlugInActionCodes* action )
- {
- ODNameSpaceManager* nameSpMgr;
- ODNameSpace* objNameSpace;
- ODSLong value;
- Sample_ScriptRunnerAgent* agent = kODNULL;
- OSErr err = noErr;
-
- ODVolatile(agent);
-
- SOM_TRY
- // First check to see if AppleScript is present. Only
- // if it is present do we proceed.
- err = Gestalt(gestaltAppleScriptAttr, &value);
-
- if ( !err && (value & (1<<gestaltAppleScriptPresent)) )
- {
- nameSpMgr = ODGetSession(ev, draft)->GetNameSpaceManager(ev);
-
- objNameSpace = nameSpMgr->HasNameSpace(ev, kOSAScriptingTool);
-
- if ( objNameSpace == kODNULL )
- {
- objNameSpace = nameSpMgr->CreateNameSpace(ev, kOSAScriptingTool,
- kODNULL, (ODULong)1, kODNSDataTypeODObject);
-
- agent = new Sample_ScriptRunnerAgent;
- THROW_IF_NULL(agent);
-
- ((ODObjectNameSpace*)objNameSpace)->Register(ev, kOSAScriptingTool, agent);
- }
- }
-
- *action = kODShellPlugInNoAction;
-
- SOM_CATCH_ALL
- err = ErrorCode();
- SOM_ENDTRY
-
- return err;
- }
-